<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\OrderRefund
 *
 * @property int $refund_id
 * @property int $buyer_uid
 * @property int $seller_uid
 * @property int $shop_id
 * @property int $order_id
 * @property string $refund_no
 * @property int $refund_type
 * @property int $refund_status
 * @property string $refund_reason
 * @property string $refund_desc
 * @property float $refund_fee 退款费用
 * @property string $refund_at
 * @property int $seller_accepted 卖家已受理
 * @property int $seller_accept_type 卖家处理类型，1=接收，2=拒绝
 * @property string $seller_accept_time
 * @property string $seller_reply_text
 * @property-read \App\Models\Order $order
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereBuyerUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundFee($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereSellerAcceptTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereSellerAcceptType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereSellerAccepted($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereSellerReplyText($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereSellerUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereShopId($value)
 * @mixin \Eloquent
 * @property float $refund_amount 退款费用
 * @property string $buyer_message 买家留言
 * @property string|null $seller_message 买家回复
 * @property int|null $created_at
 * @property int|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereBuyerMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereSellerMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereUpdatedAt($value)
 * @property int $refund_express_id
 * @property string|null $refund_express_no
 * @property string|null $images
 * @property-read \App\Models\Express $express
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereImages($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundExpressId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderRefund whereRefundExpressNo($value)
 */
class OrderRefund extends Model
{
    protected $table = 'order_refund';
    protected $primaryKey = 'refund_id';
    protected $guarded = ['refund_id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });

        static::updating(function ($model){
            if (!$model->updated_at) $model->updated_at = time();
        });
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function order()
    {
        return $this->belongsTo(Order::class, 'order_id', 'order_id');
    }

    public function express()
    {
        return $this->hasOne(Express::class, 'id', 'refund_express_id');
    }
}
